package com.spring5.learning.strategy;

import java.util.Optional;

import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author xin
 * @version 1.0
 */
public class Main {

    @Test
    public void cal() {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
        MemberStrategyContext context = ctx.getBean(MemberStrategyContext.class);
        System.out.println(context.calculate(MemberType.SUPER));

    }


    @Test
    public void op() {
        String str = null;
        System.out.println(orElse(str, "hello"));
        str = Optional.ofNullable(str).orElseGet(() -> String.valueOf(1));
        System.out.println(str);
    }

    private <T> T orElse(T t, T def) {
        return Optional.ofNullable(t).orElse(def);
    }

}
